<?php	require_once(dirname(__FILE__).'/inc/config.inc.php');IsModelPriv('fang');



/*

**************************

(C)2010-2015 phpMyWind.com

update: 2014-5-27 19:48:43

person: Feng

**************************

*/





//初始化参数

$action  = isset($action)  ? $action  : '';

$keyword = isset($keyword) ? $keyword : '';

//global $lpid,$areaid,$jsid,$zongjia,$keyword;

$lpid = isset($lpid) ? $lpid : '';

$areaid = isset($areaid) ? $areaid : '';

$jsid = isset($jsid) ? $jsid : '';

$zongjia = isset($zongjia) ? $zongjia : '';

$hxid = isset($hxid) ? $hxid : '';







//删除单条记录

if($action == 'del')

{



	$deltime = time();

	$dosql->ExecNoneQuery("UPDATE `#@__$tbname` SET delstate='true', deltime='$deltime' WHERE id=$id");

}





//删除选中记录

if($action == 'delall')

{

	if($ids != '')

	{

		//解析id,验证是否有删除权限

		$ids = explode(',',$ids);

		$idstr = '';

		foreach($ids as $id)

		{



				$idstr .= $id.',';



		}

		$idstr .= trim($idstr,',');



		if($idstr != '')

		{

			$deltime = time();

			$dosql->ExecNoneQuery("UPDATE `#@__$tbname` SET delstate='true', deltime='$deltime' WHERE `id` IN ($idstr)");

		}

	}

}

?>

<div class="toolbarTab">
  <div  class="tool1"><span class="btn btn-success" onclick="getFangAll()"><span class="icon-list-alt icon-white"></span> 全部房屋</span></div>
  <div class="tool2 row">
    <div class="span4"><span class="icon-map-marker"></span> 区域：
      <select name="areaid" id="areaid" onchange="XuanQuYu()">
        <option value="-1">请选择区域</option>
        <?php

					$dosql->Execute("SELECT * FROM `#@__cascadedata` WHERE `datagroup`='area' order by orderid ASC");

					while($row = $dosql->GetArray())

					{

						if($areaid == $row['datavalue'])

							$selected = 'selected="selected"';

						else

							$selected = '';

						echo '<option value="'.$row['datavalue'].'" '.$selected.'>'.$row['dataname'].'</option>';

					}

					?>
      </select>
    </div>
    <div class="span4"> <span class="icon-home"></span> 居室：
      <select name="jsid" id="jsid" onchange="XuanQuYu()">
        <option value="-1">请选择居室类型</option>
        <?php

					$dosql->Execute("SELECT * FROM `#@__cascadedata` WHERE `datagroup`='room' order by orderid ASC");

					while($row = $dosql->GetArray())

					{

						if($jsid == $row['datavalue'])

							$selected = 'selected="selected"';

						else

							$selected = '';

						echo '<option value="'.$row['datavalue'].'" '.$selected.'>'.$row['dataname'].'</option>';

					}

					?>
      </select>
    </div>
    <div class="span4"> <span class="icon-filter"></span> 价格：
      <select name="zongjia" id="zongjia" onchange="XuanQuYu()">
        <option value="-1">总价</option>
        <?php

					$dosql->Execute("SELECT * FROM `#@__cascadedata` WHERE `datagroup`='price' order by orderid ASC");

					while($row = $dosql->GetArray())

					{

						if($zongjia == $row['datavalue'])

							$selected = 'selected="selected"';

						else

							$selected = '';

						echo '<option value="'.$row['datavalue'].'" '.$selected.'>'.$row['dataname'].'</option>';

					}

					?>
      </select>
    </div>
    <div class="span5">
      <input  type="hidden" name="hxid" id="hxid" value="<?php echo $hxid;?>"/>
      房屋名称：
      <input type="text" class="input-medium search-query" name="keyword" id="keyword" title="输入标题名进行搜索" value="<?php echo $keyword; ?>">
      <a href="javascript:;" onclick="GetSearchFang();"  class="btn" >搜索</a> </div>
  </div>
</div>
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="ajaxlist" class="dataTable">
  <tr align="left" class="head">
    <td width="5%" height="36" class="firstCol"><input type="checkbox" name="checkid" id="checkid" onclick="CheckAll(this.checked);"></td>
    <td width="3%">ID</td>
    <td width="15%">户型图</td>
    <td width="15%">房间</td>
    <td width="20%">房屋详情</td>
    <td width="15%">更新时间</td>
    <td width="15%">销售管理</td>
    <td width="15%" class="endCol">操作</td>
  </tr>
  <?php



	//检查全局分页数

	if(empty($cfg_pagenum))  $cfg_pagenum = 20;





	//权限验证

	if($cfg_adminlevel != 1)

	{

		//初始化参数

		$catgoryListPriv   = '';

		$catgoryUpdatePriv = array();

		$catgoryDelPriv    = array();



		$dosql->Execute("SELECT * FROM `#@__adminprivacy` WHERE `groupid`=".$cfg_adminlevel."  ");

		while($row = $dosql->GetArray())

		{

			//查看权限

			if($row['action'] == 'list')

				$catgoryListPriv .= $cfg_lpid.',';



			//修改权限

			if($row['action'] == 'update')

				$catgoryUpdatePriv[] = $cfg_lpid;



			//删除权限

			if($row['action'] == 'del')

				$catgoryDelPriv[]    = $cfg_lpid;



		}



		$catgoryListPriv = trim($catgoryListPriv,',');

	}





	//设置sql

$sql = "SELECT f.*,d.dataname as areaname,h.title as huxingname,l.title as loupanname,l.tel as tel FROM `#@__$tbname` as f

					left join `#@__cascadedata`  as d on d.datavalue=f.areaid  

					left join `#@__huxing` 		 as h on h.id = f.hxid 

					left join `#@__loupan`  	 as l on l.id = f.lpid 

					WHERE  d.datagroup='area' AND f.checkinfo='true' AND f.delstate=''";



	if(!empty($keyword)) {$keyword=addslashes($keyword);$sql .= " AND f.title LIKE '%$keyword%'";}

	if(!empty($lpid)) $sql .= " AND f.lpid=$lpid  ";

	if(!empty($areaid)) $sql .= " AND f.areaid=$areaid  ";

	if(!empty($jsid)) $sql .= " AND f.jsid=$jsid  ";

	if(!empty($hxid)) $sql .= " AND f.hxid=$hxid  ";

	

	if(!empty($zongjia)){ 

			switch($zongjia){ 

				case "1": 

				$sql.="  AND  f.zongjia <= 50";    //价格 

				break; 

				case "2": 

				$sql.="  AND  (f.zongjia>=50 AND f.zongjia<=70)"; 

				break; 

				case "3": 

				$sql.="  AND  (f.zongjia>=70.00 AND f.zongjia<=100)"; 

				break; 

				case "4": 

				$sql.="  AND  (f.zongjia>=100 AND  f.zongjia<=150)"; 

				break; 

				case "5": 

				$sql.="  AND  f.zongjia>=150"; 

				break; 

		}

	}







	$dopage->GetPage($sql);

	while($row = $dosql->GetArray())

	{



		//标题名称

		$title  = '<span class="title" >'.$row['title'];

		$title .= '</span>';







		//获取审核状态

		switch($row['checkinfo'])

		{

			case 'true':

				$checkinfo = '已审';

				break;

			case 'false':

				$checkinfo = '未审';

				break;

			default:

				$checkinfo = '没有获取到参数';

		}

		

		//获取房屋的销售状态

		switch($row['is_sale'])

		{

			case 'true':

				$saleinfo = '已售';

				$a_class="btn btn-danger";

				break;

			case 'false':

				$saleinfo = '在售';

				$a_class="btn btn-success";

				break;

			default:

				$saleinfo = '没有获取到参数';

		}





		//修改权限

		if($cfg_adminlevel != 1)

		{

			if(in_array($row['lpid'], $catgoryUpdatePriv))

				$updateStr = '<a href="fang_update.php?cid='.$lpid.'&id='.$row['id'].'">修改</a>';

			else

				$updateStr = '修改';

		}

		else

		{

			$updateStr = '<a href="fang_update.php?cid='.$lpid.'&id='.$row['id'].'">修改</a>';

		}



		//修改权限

		if($cfg_adminlevel != 1)

		{

			if(in_array($row['lpid'], $catgoryDelPriv))

				$delStr = '<a href="javascript:;" onclick="ClearInfoFang('.$row['id'].')">删除</a>';

			else

				$delStr = '删除';

		}

		else

		{

				$delStr = '<a href="javascript:;" onclick="ClearInfoFang('.$row['id'].')">删除</a>';

		}









		//审核权限

		if($cfg_adminlevel != 1)

		{

			if(in_array($row['lpid'], $catgoryUpdatePriv))

				$checkStr = '<a  href="javascript:;" title="点击进行审核与未审操作" onclick="CheckInfo('.$row['id'].',\''.$checkinfo.'\')">'.$checkinfo.'</a>';

			else

				$checkStr = $checkinfo;

		}

		else

		{

			$checkStr = '<a href="javascript:;" title="点击进行审核与未审操作" onclick="CheckInfo('.$row['id'].',\''.$checkinfo.'\')">'.$checkinfo.'</a>';

		}

		

		//审核销售

		if($row['is_sale']=='true'){ $a_class="btn btn-danger";}

		if($cfg_adminlevel != 1)

		{

			if(in_array($row['lpid'], $catgoryUpdatePriv))

				$saleStr = '<a  class="'.$a_class.'" href="javascript:;" title="点击进行已售与在售操作" onclick="SaleOut('.$row['id'].',\''.$saleinfo.'\')">'.$saleinfo.'</a>';

			else

				$saleStr = $saleinfo;

		}

		else

		{

			$saleStr = '<a  class="'.$a_class.'" href="javascript:;" title="点击进行已售与在售操作" onclick="SaleOut('.$row['id'].',\''.$saleinfo.'\')">'.$saleinfo.'</a>';

		}

		

	?>
  <tr align="left" class="dataTr" onmouseover="this.className='dataTrOn'" onmouseout="this.className='dataTr'">
    <td height="36" class="firstCol"><input type="checkbox" name="checkid[]" id="checkid[]" value="<?php echo $row['id']; ?>" /></td>
    <td><?php echo $row['id']; ?></td>
    <td><span class="thumbs"><img src="/<?php echo $row['picurl']; ?>" width="100" height="75"  /></span></td>
    <td><h4 class="red"> <?php echo $title; ?> </h4>
      <?php echo $row['loupanname']; ?><br />
      区域：<?php echo $row['areaname']; ?><br />
      电话：<?php echo $row['tel']; ?>
      </td>
    <td><h4>户型:<?php echo $row['huxingname']; ?> </h4>
      <h5 class="red">
      面积：<?php echo $row['mianji']; ?> ㎡
      </h4>
      <h5 class="red">
      总价：<?php echo $row['zongjia']; ?> 万元
      </h4></td>
    <td class="number"><?php echo GetDateTime($row['posttime']); ?><br />
      发布人：<?php echo $row['author']; ?></td>
    <td><span id="sale<?php echo $row['id']; ?>" ><?php echo $saleStr;?></span></td>
    <td class="action endCol"><span id="check<?php echo $row['id']; ?>"><?php echo $checkStr; ?></span> | <span><?php echo $updateStr; ?></span> | <span class="nb"><?php echo $delStr; ?></span></td>
  </tr>
  <?php

	}

	?>
</table>
<?php



//判断无记录样式

if($dosql->GetTotalRow() == 0)

{

	echo '<div class="dataEmpty">暂时没有相关的记录</div>';

}?>
<div class="page"> <?php echo $dopage->AjaxFangPage(); ?> </div>
<?php

		//审核销售

if($cfg_adminlevel == 1)

{



?>
<div class="bottomToolbar"> <span class="selArea"><span>选择：</span> <a href="javascript:CheckAll(true);">全部</a> - <a href="javascript:CheckAll(false);">无</a> - <a href="javascript:;" onclick="AjaxClearAllFang();">删除</a></span> <a href="loupan_add.php" class="dataBtn">添加新房信息</a></span> </div>
<?php

}

//判断是否启用快捷工具栏

if($cfg_quicktool == 'Y'  && $cfg_adminlevel == 1)

{

?>
<div class="quickToolbar">
  <div class="qiuckWarp">
    <div class="quickArea"><span class="selArea"><span>选择：</span> <a href="javascript:CheckAll(true);">全部</a> - <a href="javascript:CheckAll(false);">无</a> - <a href="javascript:;" onclick="AjaxClearAllFang();">删除</a></span> <a href="fang_add.php" class="dataBtn">添加新房信息</a> <span class="pageSmall"><?php echo $dopage->AjaxPageSmall(); ?></span> </div>
    <div class="quickAreaBg"></div>
  </div>
</div>
<?php

}



?>
